using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using System.Collections;
using System.Data;
namespace DAOLayer
{
    public class DangKyDAO:AbStractDao
    {
        public DangKyDAO()
        {
            this.connect();
        }
        
        public static DataTable getListDangKy()
        {
            string query = "SELECT * FROM DangKy";
            DangKyDAO dgDao = new DangKyDAO();
            DataTable dt = dgDao.fillDataTable(query);
            dgDao.disconnect();           
            return dt;
        }
        public static DangKyDTO getDangKy(int maDangKy)
        {
            string strQuery = "select * from DangKy where MaDangKy= " + maDangKy;
            DangKyDAO dgDao = new DangKyDAO();
            IDataReader dr = dgDao.executeQuery(strQuery);
            DangKyDTO dgDto = new DangKyDTO();
            if (dr.Read())
            {
                dgDto.MaDangKy = dr.GetInt32(0);
                dgDto.MaDocGia = dr.GetInt32(1);
                dgDto.MaCuonSach = dr.GetInt32(2);
                dgDto.NgayDangKy = dr.GetDateTime(3);
                dgDto.GhiChu = dr.GetString(4);
            }
            dgDao.disconnect();
            return dgDto;
        }
        public bool insert(ref DangKyDTO info)
        {

            string insertCommand = "INSERT INTO DangKy(MaDocGia,MaCuonSach,NgayDangKy,GhiChu) VALUES(" +
                info.MaDocGia + ", " +
                info.MaCuonSach + ", '" +
                info.NgayDangKy + "', '" +
                info.GhiChu + "')";
            bool flag = executeNonQuery(insertCommand);     
            return flag;
        }
        public bool update(DangKyDTO info)
        {
            string updateCommand = "UPDATE DangKy " +
                                    "SET MaCuonSach = '" + info.MaCuonSach +  "', NgayDangKy='" + info.NgayDangKy + ", GhiChu='" + info.GhiChu +                                 
                                    "' WHERE MaDangKy = " + info.MaDangKy ;
            bool flag = this.executeNonQuery(updateCommand);
    
            return flag;
        }
        public bool delete(int maDangKy)
        {
            string deleteCommand = "DELETE FROM DangKy WHERE MaDangKy = " + maDangKy;
            bool flag = this.executeNonQuery(deleteCommand);
            return flag;
        }
    }
}
